package test.service

import io.github.frailty9.crserver.dso.service.AccountService
import io.github.frailty9.crserver.model.Account
import org.junit.jupiter.api.Test
import org.noear.solon.annotation.Inject
import org.noear.solon.data.annotation.Transaction
import org.noear.solon.test.SolonTest
import org.noear.solon.test.annotation.Rollback
import java.time.LocalDateTime

@Rollback
@SolonTest(io.github.frailty9.crserver.App::class)
open class AccountServiceTest {

    @Inject
    lateinit var accountService: AccountService

    @Rollback
    @Transaction
    @Test
    fun testSave() {
        val account = Account(
            id = null,
            username = "test",
            password = "password",
            role = "student",
            version = 0,
            createTime = null,
            updateTime = null,
            deleted = 0
        )
        accountService.save(account)
    }

    @Rollback
    @Transaction
    @Test
    fun testAutoSetTimeToNull() {
        val account = Account(
            id = null,
            username = "test",
            password = "password",
            role = "student",
            version = 0,
            createTime = LocalDateTime.now(),
            updateTime = null,
            deleted = 0
        )
        accountService.save(account)
        assert(account.createTime == null)
    }
}